package com.lj.bruth.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.io.FileUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import com.lj.bruth.model.User;
import com.lj.bruth.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.awt.*;
import java.io.File;
import java.util.List;
import java.util.logging.Logger;

//域名：www.bruthli.top

@Controller
@RequestMapping(value="/user")
public class HelloController {

    private static Logger logger = Logger.getLogger(HelloController.class.getName());

    @Autowired
    private UserService userService;

    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;


//    @RequestMapping(value="/queryUser",method=RequestMethod.GET)
//    @ResponseBody
//    public List<User> queryUser() {
//        List<User>list = userService.queryUser();
//        DateTime of = DateTime.of("2029-09-09 11:12:12", "yyyy-MM-dd");
//        int i = of.dayOfMonth();
//        System.out.println("================"+i);
//        return list;
//    }

//    @RequestMapping(value="/insertAndResisUser",method=RequestMethod.POST)
//    @ResponseBody
//    public User insertAndResisUser(@RequestBody User user) {
//        User userNew = null;
//        try {
//            userNew = userService.insertAndResisUser(user);
//            logger.info("存储redis和数据库数据是：userNew");
//        }catch (Exception e){
//            logger.info("数据处理错误！！！");
//        }
//        return userNew;
//    }

    @RequestMapping(value="/setAndGetRedisData",method=RequestMethod.GET)
    @ResponseBody
    public String setAndGetRedisData() {
        stringRedisTemplate.opsForValue().set("jkl1","jiji");
        String jkl = stringRedisTemplate.opsForValue().get("jkl1");
        return "兄弟洗东西===="+String.valueOf(jkl);
    }

    //二维码报错没有解决！！
    @RequestMapping(value="/getErCode",method=RequestMethod.GET)
    @ResponseBody
    public String getErCode() {
        QrConfig config = new QrConfig(300, 300);
        // 设置边距，既二维码和背景之间的边距
        config.setMargin(3);
        // 设置前景色，既二维码颜色（青色）
        config.setForeColor(Color.CYAN.getRGB());
        // 设置背景色（灰色）
        config.setBackColor(Color.GRAY.getRGB());
        //config.setImg("e:/logo_small.jpg"), //附带logo
        // 生成指定url对应的二维码到文件，宽和高都是300像素
        File generate = QrCodeUtil.generate("https://hutool.cn/", config, FileUtil.file("/Users/java/qrcode.jpg"));
        return generate.getAbsolutePath();
    }




}
